package com.sf.web.controller;

import com.sf.domain.Department;
import com.sf.domain.Employee;
import com.sf.service.IDepartmentService;
import com.sf.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @RequestMapping("/department/list")
    @ResponseBody
    public JsonResult department() {
            return new JsonResult(true, "操作成功", departmentService.list());
    }

    @RequestMapping("/department/delete")
    @ResponseBody
    public JsonResult delete(Long id){
        departmentService.delete(id);
         return new JsonResult(true,"操作成功",null);
        }
     @RequestMapping("/department/save")
    @ResponseBody
    public JsonResult save(@RequestBody  Department department){
        departmentService.save(department);
        return new JsonResult(true,"操作成功",null);
     }
     @RequestMapping("/department/update")
    @ResponseBody
    public JsonResult update(@RequestBody Department department){
        departmentService.update(department);
        return new JsonResult(true,"操作成功",null);
     }
    @RequestMapping("/department/get")
    @ResponseBody
    public JsonResult get(Long id){
        Department department = departmentService.get(id);
        return new JsonResult(true,"操作成功",department);
    }
    }




